package ru.hh.school.commands;

import ru.hh.school.User;
import ru.hh.school.logging.Logger;

import java.util.List;

import static ru.hh.school.Constants.LINE_SEPARATOR;
import static ru.hh.school.MessagesManager.message;

public class HelpCommand extends AbstractCommand {
    private final String listOfAllCommandsString;

    public HelpCommand(Logger logger, List<Command> commands) {
        super(logger);
        this.listOfAllCommandsString = constructListOfAllCommandsString(commands);
    }

    private String constructListOfAllCommandsString(List<Command> commands) {
        //TODO make it easier, reuse StringUtils join or smth
        //TODO no need in LineSep after last line
        StringBuilder builder = new StringBuilder();
        for (Command cmd : commands) {
            builder.append(cmd.getCommand()).append(" - ").append(cmd.getDescription()).append(LINE_SEPARATOR);
        }
        return message("command.help.notify.user.list.of.all.commands", builder.toString());
    }

    public String getCommand() {
        return "/help";
    }

    public String getDescription() {
        return message("command.help.description");
    }

    public void process(User user, String data) {
        user.sendMessage(listOfAllCommandsString);
    }
}